﻿/*
 * ========================================================================
 * Copyright(c) 2007-2012 情留メ蚊子, All Rights Reserved.
 * Welcom use the LiteFetion.
 * See more information,Please goto http://www.94qing.com
 * ========================================================================
 * 
 * 作 者：情留メ蚊子
 * Q  Q: 540644769
 * 邮 箱：qlwz@qq.com
 * 网 址：http://www.94qing.com
 * ========================================================================
*/
using LiteFetion.Model;
using Newtonsoft.Json.Linq;

namespace LiteFetion.Notify
{
    /// <summary>
    /// 客户端状态通知
    /// </summary>
    public class ClientStateNotify
    {
        public ClientStateNotify(FetionClient client, ClientState clientState)
        {
            this.ClientState = clientState;
            Event.OnClientStateNotify(this);
        }

        public ClientStateNotify(FetionClient client, JObject data)
        {
            int exitCode = data.Value<int>("ec");
            this.ClientState = ClientState.LOGOUT;
            if (exitCode == 900)
            {
                this.ClientState = ClientState.OTHER_LOGIN;
            }
            else if (exitCode >= 902 && exitCode <= 905)
            {
                this.ClientState = ClientState.LOGOUT;
            }
            else
            {
                this.ClientState = ClientState.LOGOUT;
            }
            Event.OnClientStateNotify(this);
        }

        /// <summary>
        /// FetionClient
        /// </summary>
        public FetionClient FetionClient { get; private set; }

        /// <summary>
        /// 客户端状态
        /// </summary>
        public ClientState ClientState { get; private set; }

        public override string ToString()
        {
            return "ClientStateNotify [ClientState=" + this.ClientState + "]";
        }
    }
}
